import { Body, Controller, Del, Inject, Param, Post } from '@midwayjs/core'
import {
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
  ApiTags
} from '@midwayjs/swagger'
import { Validate } from '@midwayjs/validate'

import { Permission } from '@/decorator'

import { FindOnlinePageDTO } from './online.dto'
import { OnlineService } from './online.service'
import { GetOnlinePageVO } from './online.vo'

@ApiBearerAuth()
@ApiTags('监控/在线接口')
@Controller('/monitor/online')
export class OnlineController {
  @Inject()
  onlineService: OnlineService

  @ApiOperation({ summary: '获取在线分页' })
  @ApiResponse({ status: 200, type: GetOnlinePageVO })
  @Permission('monitor:online:list')
  @Post('/page')
  @Validate()
  async getOnlinePage(@Body() dto: FindOnlinePageDTO) {
    return await this.onlineService.handleFindPage(dto)
  }

  @ApiOperation({ summary: '下线' })
  @Permission('monitor:online:delete')
  @Del('/:id')
  async offline(@Param('id') id: string) {
    await this.onlineService.handleOffline(id)
  }
}
